package com.ybkj.o2o.sales.manager.impl;

import com.ybkj.o2o.sales.common.DataGrid;
import com.ybkj.o2o.sales.entity.ActivityRecord;
import com.ybkj.o2o.sales.manager.ActivityRecordManager;
import com.ybkj.o2o.sales.service.ActivityRecordService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DefaultActivityRecordManager implements ActivityRecordManager {


  @Autowired
  private ActivityRecordService activityRecordService;


  @Override
  public DataGrid<ActivityRecord> queryByActivity(Long activityId, Long companyId, String phone,
      Date startTime, Date endTime, Integer page, Integer rows, String appKey) {
    Integer offset = 0;
    if (page != null && rows != null) {
      offset = (page - 1) * rows;
    }

    List<ActivityRecord> list =
        activityRecordService.queryByActivity(activityId, companyId, phone, startTime, endTime,
            offset, rows, appKey);
    long count =
        activityRecordService.countByActivity(activityId, companyId, phone, startTime, endTime,
            appKey);

    DataGrid<ActivityRecord> dataGrid = new DataGrid<ActivityRecord>();
    dataGrid.setRows(list);
    dataGrid.setTotal(count);

    return dataGrid;
  }


  @Override
  public Long countByActivityAndPassenger(Long activityId, Long passengerId, String appKey) {
    return activityRecordService.countByActivityAndPassenger(activityId, passengerId, appKey);
  }


  @Override
  public ActivityRecord findOne(Long recordId, String appKey) {
    ActivityRecord activityRecord = activityRecordService.findOne(recordId, appKey);

    return activityRecord;
  }


  @Override
  public Long countActivityRecord(Long activityId, Long companyId, String phone, Date startTime,
      Date endTime, String appKey) {
    return activityRecordService.countByActivity(activityId, companyId, phone, startTime, endTime,
        appKey);
  }



}
